package com.gitee.wsl.math.matrix.tran

import com.gitee.wsl.math.matrix.Matrix
import com.gitee.wsl.math.matrix.MatrixVisitor
import com.gitee.wsl.math.matrix.MutableMatrix

object Transpose:MatrixVisitor<MutableMatrix>{
    override fun <M : Matrix> visitor(src: M, nextChin:((i:Int, j:Int, value:Float)->Float)?): MutableMatrix {
        src.run {
           val tv = Array(m_nCols) {
               FloatArray(
                   m_nRows
               )
           }

           // transposed values
           // Set the values of the transpose.
           var calcValue:Float
           for (r in 0 until m_nRows) {
               for (c in 0 until m_nCols) {
                   calcValue = m_aValues[r][c]
                   tv[c][r] = nextChin?.invoke(r,c,calcValue)?:calcValue
               }
           }
           return MutableMatrix(tv)
       }
    }
}